<template>
  <div>
    <div class="ccInfo">
      <img :src="coursePublish.cover" alt="">
      <div class="main">
        <h2>{{coursePublish.title}}</h2>
        <p class="gray"><span>共{{coursePublish.lessonNum}}课时</span></p>
        <p><span>所属分类：{{coursePublish.subject}}</span></p>
        <p>课程讲师：{{coursePublish.teacher}}</p>
        <h3 class="red">￥{{coursePublish.price}}</h3>
      </div>
    </div>

    <el-form style="text-align: center">
      <el-form-item>
        <el-button @click="prve">返回上一步</el-button>
        <el-button type="primary" @click="pub">最终发布</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    import http from "@/api/course"
    import TeacherHttp from "@/api/teacher"
    import SubjectHttp from "@/api/subject"

    export default {
        name: "publish",
        props:{
            globalCourse: '',
        },
        data(){
            return{
                coursePublish:{
                    cover:this.globalCourse.cover,
                    title:this.globalCourse.title,
                    lessonNum:this.globalCourse.lessonNum,
                    price:this.globalCourse.price,
                    subject:'',
                    teacher:'',
                }
            }
        },
        methods:{
            prve(){
                this.$emit("prve")
            },
            pub(){
                http.publishCourse(this.globalCourse.id).then(res=>{
                    if (res.data){
                        const loading = this.$loading({
                            lock: true,
                            text: '正在发布...',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)',
                            target:".ccInfo"
                        });
                        setTimeout(() => {
                            loading.close();
                            this.$message({
                                type: "success",
                                message: "发布成功"
                            })
                            this.$router.push("/course/list")
                        }, 2000);
                    }
                })
            },
            init(){
                SubjectHttp.getSubjectById(this.globalCourse.subjectId).then(res=>{
                    this.coursePublish.subject = res.data.title
                })
                TeacherHttp.getTeacherById(this.globalCourse.teacherId).then(res=>{
                    this.coursePublish.teacher = res.data.name
                })

            }
        },
        created() {
            this.init()
        }
    }
</script>

<style scoped>
  .ccInfo{
    background: #f5f5f5;
    padding: 20px;
    overflow: hidden;
    border: 1px dashed #DDD;
    margin-bottom: 40px;
    position: relative;
  }
  .ccInfo img{
    background: #d6d6d6;
    width: 500px;
    height: 278px;
    display: block;
    float: left;
    border: none;
  }
  .ccInfo .main{
    margin-left: 520px;
  }
  .ccInfo .main h2{
    font-size: 28px;
    margin-bottom: 30px;
    line-height: 1;
    font-weight: normal;
  }
  .ccInfo .main p{
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
  }
  .ccInfo .main h3{
    left: 540px;
    bottom: 20px;
    line-height: 1;
    font-size: 28px;
    color: #d32f24;
    font-weight: normal;
    position: absolute;
  }
</style>
